<!--detail-->
<table>
    <tbody id="salesOrderDetailFooter">
    	<tr>
    		<td>
    			<label for="searchProductNumber"><g:message code="b2b.salesOrderDetail.search.product" default="Search Product" />:</label>
		        <g:textField name="searchProductNumber" style="width:300px;"/>
		        <g:hiddenField name="searchProductId"/>
		        <span id="searchProductName"></span>
		        ,<span id="searchProductStandard"></span>
		        ,<span id="searchProductPrice"></span>
			</td>
    	</tr>
    </tbody>
</table>
<table>
    <thead>
        <tr>
            <th><g:message code="b2b.salesOrderDetail.serialNumber" default="Serial Number" /></th>
            <th><g:message code="b2b.salesOrderDetail.product" default="Product" /></th>
            <th><g:message code="b2b.product.name" default="Product Name" /></th>
            <th><g:message code="b2b.product.standard" default="Standard" /></th>
            <th><g:message code="b2b.product.category" default="Category" /></th>
            <th>
                <g:message code="b2b.salesOrderDetail.price" default="Price" />
                (<g:message code="b2b.category.isAllowZeroPrice" default="Allow Zero Price?" />)
            </th>
            <th><g:message code="b2b.salesOrderDetail.discount" default="Discount" /></th>
            <th>
                <g:message code="b2b.salesOrderDetail.quantity" default="Order Quantity" />
            </th>
            <th>
                <g:message code="b2b.salesOrderDetail.deliveryLimitation" default="Delivery Limitation" />
                (<g:message code="b2b.category.deliveryCycle" default="Delivery Cycle" />)
            </th>
            <th><g:message code="b2b.salesOrderDetail.amount" default="Amount" /></th>
        </tr>
    </thead>
    <tbody id="salesOrderDetailList">
    <g:set var="_total_amount" value="${0}"/>
    <g:each in="${salesOrderInstance.salesOrderDetails}" status="i" var="salesOrderDetailInstance">
        <!--row amount-->
        <g:set 
            var="_amount" 
            value="${(salesOrderDetailInstance?.amount)?:(salesOrderDetailInstance?.price * salesOrderDetailInstance?.discount * salesOrderDetailInstance?.quantity)}" />
       	<g:set var="_total_amount" value="${_total_amount + _amount?:0}"></g:set>
        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
        	<td name="serialNumber">
            	<span>${fieldValue(bean: salesOrderDetailInstance, field: "serialNumber")}</span>
            	<g:hiddenField name="salesOrderDetails[${i}].serialNumber" value="${salesOrderDetailInstance?.serialNumber}"/>
            	<br/>
            	<a href="#addSalesOrderDetailLink" delete="delete">${message(code: 'default.button.delete', default: 'Delete')}</a>
            </td>
            <td name="product.id">
            	${fieldValue(bean: salesOrderDetailInstance, field: "product")}
            	<g:hiddenField name="salesOrderDetails[${i}].product.id" value="${salesOrderDetailInstance?.product?.id}"/>
            </td>
            <td name="product.name">${fieldValue(bean: salesOrderDetailInstance, field: "product.name")}</td>
            <td name="product.standard">${fieldValue(bean: salesOrderDetailInstance, field: "product.standard")}</td>
            <td name="category">
            	${include(controller : 'salesOrderAjax', action : 'productCategoryOfCG', params : [product : salesOrderDetailInstance?.product?.serialNumber] )}
            </td>
            <td class="value ${hasErrors(bean: salesOrderInstance, field: 'salesOrderDetails.price', 'errors')} number" name="price">
            	<g:textField 
                    name="salesOrderDetails[${i}].price" 
                    value="${formatNumber( number : salesOrderDetailInstance?.price, format:'###,##0.000000')}" readonly="readonly"/>
                <span>
            		(<g:include controller="salesOrderAjax" action="isAllowZeroPrice" params="[product:salesOrderDetailInstance?.product?.serialNumber]"/>)
            	</span>
            </td>
            <td class="value ${hasErrors(bean: salesOrderInstance, field: 'salesOrderDetails.discount', 'errors')} number" name="discount">
            	<g:textField 
                    name="salesOrderDetails[${i}].discount" 
                    value="${formatNumber( number : salesOrderDetailInstance?.discount, format:'###,##0.0000')}" readonly="readonly"/>
            </td>
            <td class="value ${hasErrors(bean: salesOrderInstance, field: 'salesOrderDetails.quantity', 'errors')} number" name="quantity" >
            	<g:textField name="salesOrderDetails[${i}].quantity" value="${formatNumber( number : salesOrderDetailInstance?.quantity, format:'###,##0.00')}"/>
            </td>
            <td class="value ${hasErrors(bean: salesOrderInstance, field: 'salesOrderDetails.deliveryLimitation', 'errors')}" name="deliveryLimitation">
            	<g:jqDatePicker name="salesOrderDetails[${i}].deliveryLimitation" value="${salesOrderDetailInstance?.deliveryLimitation}"/>
            	<span>
            		<g:include controller="salesOrderAjax" action="deliveryCycle" params="[product:salesOrderDetailInstance?.product?.serialNumber]"/>
            	</span>
			</td>
            <td class="value number" name="amount" >
                <g:formatNumber number="${_amount}" format="###,##0.0000" />
            </td>
        </tr>
    </g:each>
    </tbody>
    <tfoot>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>
            	<label for="totalAmount"><g:message code="b2b.salesOrder.salesOrderDetails.amount.sum" default="Total Amount" /></label>
            </td>
            <td name="totalAmount">
            	<g:formatNumber number="${_total_amount?:0}" format="###,##0.0000" />
            </td>
            <td>&nbsp;</td>
        </tr>
    </tfoot>
</table>
<!--end detail-->
